package home_page

import (
	"api/internal/respons"
	"context"
	"homepage_srv/homepage"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GoodListLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGoodListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GoodListLogic {
	return &GoodListLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

// 商品列表
func (l *GoodListLogic) GoodList(req *types.GoodListRequest) (resp *types.Response, err error) {
	search, err := l.svcCtx.HomepageGrpc.GoodList(l.ctx, &homepage.GoodListRequest{
		CateId: req.CateId,
	})

	if err != nil {
		return respons.Error(400, "商品列表查询失败", nil), err
	}

	return respons.Success(search), nil
}
